param( $ManifestDiff
     , [string]	$SourceDir=$(Throw "Parameter SourceDir is required")
     , [string]	$DestinationDir=$(Throw "Parameter DestinationDir is required")
     , [string]	$SyncPackageDir=$(Throw "Parameter SyncPackageDir is required")
     , [switch]	$Whatif
     , [switch]	$Force
     )

begin
{
	
	function CreateSyncPackage($ManifestDiff)
	{
		foreach ($File in $ManifestDiff.Added)
		{
			$DestPath = $(PsSyncFileItemPath $file $SyncPackagePath)
			PsSyncAssureItemsDir $DestPath -WhatIf:$WhatIf
			Copy-Item $(PsSyncFileItemPath $file $SourcePath) $DestPath -Whatif:$Whatif 
		}
		
		foreach ($File in $ManifestDiff.Changed)
		{
			$DestPath = $(PsSyncFileItemPath $file $SyncPackagePath)
			PsSyncAssureItemsDir $DestPath -WhatIf:$WhatIf
			Copy-Item $(PsSyncFileItemPath $file $SourcePath) $DestPath -Whatif:$Whatif 
		}
	}

	$SourcePath = (Get-Item $SourceDir).FullName
	$DestinationPath = (Get-Item $DestinationDir).FullName

	if ( (split-path $SyncPackageDir) -eq "")
	{
		$SyncPackageDir = '.\' + $SyncPackageDir
	}
	
	$syncDir = PsSyncCreateDir $SyncPackageDir -Force:$Force
	
	$SyncPackagePath = $syncDir.FullName
	
	if ($ManifestDiff -ne $null)
	{
		CreateSyncPackage $ManifestDiff
	}

}

process
{
	if ($_ -ne $null)
	{
		CreateSyncPackage $_
	}
}
